{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Import libraries\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import psycopg2\n",
    "import os\n",
    "\n",
    "# Plot settings\n",
    "%matplotlib inline\n",
    "plt.style.use('ggplot')\n",
    "fontsize = 20 # size for x and y ticks\n",
    "plt.rcParams['legend.fontsize'] = fontsize\n",
    "plt.rcParams.update({'font.size': fontsize})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# create a database connection\n",
    "sqluser = 'postgres'\n",
    "dbname = 'eicu'\n",
    "schema_name = 'eicu_crd'\n",
    "sqlhost = 'localhost'\n",
    "sqlport = 5432\n",
    "# Connect to the database\n",
    "con = psycopg2.connect(dbname=dbname, user=sqluser, host=sqlhost, port=sqlport)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "query_schema = 'set search_path to public,eicu_crd_phi;'\n",
    "query = query_schema + \"\"\"\n",
    "with t1 as\n",
    "(\n",
    "select\n",
    "    patientunitstayid\n",
    "    , treatmentoffset\n",
    "    , case\n",
    "        when treatmentstring like 'pulmonary|ventilation and oxygenation|mechanical ventilation%' then 1\n",
    "        when treatmentstring like 'surgery|pulmonary therapies|mechanical ventilation%' then 1\n",
    "        when treatmentstring like 'toxicology|drug overdose|mechanical ventilation%' then 1\n",
    "    else 0 end as mechvent\n",
    "from treatment\n",
    ")\n",
    "select \n",
    "    patientunitstayid\n",
    "    , min(treatmentoffset) as mvstart\n",
    "    , max(treatmentoffset) as mvend\n",
    "from t1\n",
    "where mechvent = 1\n",
    "group by patientunitstayid\n",
    "order by patientunitstayid\n",
    "\"\"\"\n",
    "\n",
    "tr = pd.read_sql_query(query, con)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "query_schema = 'set search_path to public,eicu_crd_phi;'\n",
    "query = query_schema + \"\"\"\n",
    "select\n",
    "    apv.patientunitstayid\n",
    "    , oOBIntubDay1 as mv_apache\n",
    "from apachepredvar apv\n",
    "inner join apachepatientresult apr\n",
    "on apv.patientunitstayid = apr.patientunitstayid\n",
    "and apacheversion = 'IVa'\n",
    "where apr.predictedhospitalmortality != '-1'\n",
    "\"\"\"\n",
    "\n",
    "ap = pd.read_sql_query(query, con)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>mv_treatment</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>All</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mv_apache</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.726071</td>\n",
       "      <td>0.012853</td>\n",
       "      <td>0.738924</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.055536</td>\n",
       "      <td>0.205540</td>\n",
       "      <td>0.261076</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>All</th>\n",
       "      <td>0.781607</td>\n",
       "      <td>0.218393</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "mv_treatment         0         1       All\n",
       "mv_apache                                 \n",
       "0             0.726071  0.012853  0.738924\n",
       "1             0.055536  0.205540  0.261076\n",
       "All           0.781607  0.218393  1.000000"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# cross-reference\n",
    "df = ap.merge(tr, how='left', on='patientunitstayid').copy()\n",
    "df['mv_treatment'] = (df['mvstart'] < 1440).astype(int)\n",
    "\n",
    "pd.crosstab(df['mv_apache'],df['mv_treatment'], margins=True, normalize=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>patientunitstayid</th>\n",
       "      <th>mv_apache</th>\n",
       "      <th>mvstart</th>\n",
       "      <th>mvend</th>\n",
       "      <th>mv_treatment</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4709</th>\n",
       "      <td>242154</td>\n",
       "      <td>1</td>\n",
       "      <td>204.0</td>\n",
       "      <td>4683.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4732</th>\n",
       "      <td>243283</td>\n",
       "      <td>1</td>\n",
       "      <td>33.0</td>\n",
       "      <td>503.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4735</th>\n",
       "      <td>243494</td>\n",
       "      <td>1</td>\n",
       "      <td>392.0</td>\n",
       "      <td>3851.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4737</th>\n",
       "      <td>243643</td>\n",
       "      <td>1</td>\n",
       "      <td>77.0</td>\n",
       "      <td>142.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4745</th>\n",
       "      <td>243990</td>\n",
       "      <td>1</td>\n",
       "      <td>103.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4751</th>\n",
       "      <td>244255</td>\n",
       "      <td>0</td>\n",
       "      <td>-389.0</td>\n",
       "      <td>-306.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4757</th>\n",
       "      <td>244445</td>\n",
       "      <td>1</td>\n",
       "      <td>184.0</td>\n",
       "      <td>3162.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4763</th>\n",
       "      <td>244718</td>\n",
       "      <td>1</td>\n",
       "      <td>27.0</td>\n",
       "      <td>1134.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4765</th>\n",
       "      <td>244763</td>\n",
       "      <td>0</td>\n",
       "      <td>993.0</td>\n",
       "      <td>1125.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4767</th>\n",
       "      <td>244975</td>\n",
       "      <td>1</td>\n",
       "      <td>74.0</td>\n",
       "      <td>1601.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4775</th>\n",
       "      <td>245542</td>\n",
       "      <td>1</td>\n",
       "      <td>151.0</td>\n",
       "      <td>151.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4784</th>\n",
       "      <td>245956</td>\n",
       "      <td>1</td>\n",
       "      <td>118.0</td>\n",
       "      <td>1257.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4785</th>\n",
       "      <td>246128</td>\n",
       "      <td>1</td>\n",
       "      <td>87.0</td>\n",
       "      <td>87.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4787</th>\n",
       "      <td>246393</td>\n",
       "      <td>1</td>\n",
       "      <td>104.0</td>\n",
       "      <td>1609.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4790</th>\n",
       "      <td>246449</td>\n",
       "      <td>1</td>\n",
       "      <td>78.0</td>\n",
       "      <td>78.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4792</th>\n",
       "      <td>246531</td>\n",
       "      <td>1</td>\n",
       "      <td>131.0</td>\n",
       "      <td>131.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4798</th>\n",
       "      <td>246953</td>\n",
       "      <td>1</td>\n",
       "      <td>25.0</td>\n",
       "      <td>1374.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4800</th>\n",
       "      <td>247030</td>\n",
       "      <td>1</td>\n",
       "      <td>50.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4801</th>\n",
       "      <td>247048</td>\n",
       "      <td>1</td>\n",
       "      <td>45.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4802</th>\n",
       "      <td>247164</td>\n",
       "      <td>1</td>\n",
       "      <td>851.0</td>\n",
       "      <td>2255.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4803</th>\n",
       "      <td>247206</td>\n",
       "      <td>1</td>\n",
       "      <td>213.0</td>\n",
       "      <td>1471.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4804</th>\n",
       "      <td>247249</td>\n",
       "      <td>0</td>\n",
       "      <td>2088.0</td>\n",
       "      <td>2088.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4807</th>\n",
       "      <td>247296</td>\n",
       "      <td>1</td>\n",
       "      <td>149.0</td>\n",
       "      <td>4272.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4808</th>\n",
       "      <td>247363</td>\n",
       "      <td>1</td>\n",
       "      <td>142.0</td>\n",
       "      <td>540.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4809</th>\n",
       "      <td>247408</td>\n",
       "      <td>1</td>\n",
       "      <td>1259.0</td>\n",
       "      <td>8363.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4814</th>\n",
       "      <td>247748</td>\n",
       "      <td>1</td>\n",
       "      <td>32.0</td>\n",
       "      <td>32.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4820</th>\n",
       "      <td>247872</td>\n",
       "      <td>1</td>\n",
       "      <td>48.0</td>\n",
       "      <td>1038.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4821</th>\n",
       "      <td>247888</td>\n",
       "      <td>1</td>\n",
       "      <td>77.0</td>\n",
       "      <td>4168.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4828</th>\n",
       "      <td>248438</td>\n",
       "      <td>1</td>\n",
       "      <td>375.0</td>\n",
       "      <td>375.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4830</th>\n",
       "      <td>248581</td>\n",
       "      <td>1</td>\n",
       "      <td>11.0</td>\n",
       "      <td>26621.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136147</th>\n",
       "      <td>3352097</td>\n",
       "      <td>1</td>\n",
       "      <td>47.0</td>\n",
       "      <td>47.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136148</th>\n",
       "      <td>3352103</td>\n",
       "      <td>1</td>\n",
       "      <td>134.0</td>\n",
       "      <td>134.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136149</th>\n",
       "      <td>3352114</td>\n",
       "      <td>1</td>\n",
       "      <td>75.0</td>\n",
       "      <td>75.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136150</th>\n",
       "      <td>3352119</td>\n",
       "      <td>1</td>\n",
       "      <td>109.0</td>\n",
       "      <td>129.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136151</th>\n",
       "      <td>3352125</td>\n",
       "      <td>1</td>\n",
       "      <td>84.0</td>\n",
       "      <td>1304.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136153</th>\n",
       "      <td>3352178</td>\n",
       "      <td>1</td>\n",
       "      <td>145.0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136155</th>\n",
       "      <td>3352203</td>\n",
       "      <td>1</td>\n",
       "      <td>137.0</td>\n",
       "      <td>4370.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136163</th>\n",
       "      <td>3352336</td>\n",
       "      <td>1</td>\n",
       "      <td>59.0</td>\n",
       "      <td>59.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136164</th>\n",
       "      <td>3352340</td>\n",
       "      <td>1</td>\n",
       "      <td>203.0</td>\n",
       "      <td>203.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136165</th>\n",
       "      <td>3352344</td>\n",
       "      <td>1</td>\n",
       "      <td>99.0</td>\n",
       "      <td>99.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136167</th>\n",
       "      <td>3352402</td>\n",
       "      <td>1</td>\n",
       "      <td>44.0</td>\n",
       "      <td>44.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136168</th>\n",
       "      <td>3352437</td>\n",
       "      <td>1</td>\n",
       "      <td>96.0</td>\n",
       "      <td>7382.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136170</th>\n",
       "      <td>3352445</td>\n",
       "      <td>1</td>\n",
       "      <td>451.0</td>\n",
       "      <td>7922.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136176</th>\n",
       "      <td>3352526</td>\n",
       "      <td>1</td>\n",
       "      <td>321.0</td>\n",
       "      <td>7224.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136181</th>\n",
       "      <td>3352546</td>\n",
       "      <td>1</td>\n",
       "      <td>67.0</td>\n",
       "      <td>714.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136182</th>\n",
       "      <td>3352569</td>\n",
       "      <td>1</td>\n",
       "      <td>11.0</td>\n",
       "      <td>2256.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136187</th>\n",
       "      <td>3352618</td>\n",
       "      <td>1</td>\n",
       "      <td>84.0</td>\n",
       "      <td>9412.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136188</th>\n",
       "      <td>3352620</td>\n",
       "      <td>0</td>\n",
       "      <td>2051.0</td>\n",
       "      <td>2051.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136191</th>\n",
       "      <td>3352711</td>\n",
       "      <td>1</td>\n",
       "      <td>80.0</td>\n",
       "      <td>6212.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136192</th>\n",
       "      <td>3352721</td>\n",
       "      <td>1</td>\n",
       "      <td>308.0</td>\n",
       "      <td>20292.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136201</th>\n",
       "      <td>3352801</td>\n",
       "      <td>1</td>\n",
       "      <td>309.0</td>\n",
       "      <td>310.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136202</th>\n",
       "      <td>3352827</td>\n",
       "      <td>0</td>\n",
       "      <td>1192.0</td>\n",
       "      <td>21916.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136204</th>\n",
       "      <td>3352861</td>\n",
       "      <td>1</td>\n",
       "      <td>140.0</td>\n",
       "      <td>598.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136217</th>\n",
       "      <td>3352986</td>\n",
       "      <td>1</td>\n",
       "      <td>453.0</td>\n",
       "      <td>51720.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136221</th>\n",
       "      <td>3353031</td>\n",
       "      <td>1</td>\n",
       "      <td>95.0</td>\n",
       "      <td>95.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136225</th>\n",
       "      <td>3353092</td>\n",
       "      <td>1</td>\n",
       "      <td>46.0</td>\n",
       "      <td>46.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136229</th>\n",
       "      <td>3353144</td>\n",
       "      <td>1</td>\n",
       "      <td>103.0</td>\n",
       "      <td>11217.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136231</th>\n",
       "      <td>3353194</td>\n",
       "      <td>1</td>\n",
       "      <td>52.0</td>\n",
       "      <td>2212.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136232</th>\n",
       "      <td>3353226</td>\n",
       "      <td>1</td>\n",
       "      <td>81.0</td>\n",
       "      <td>10522.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>136234</th>\n",
       "      <td>3353251</td>\n",
       "      <td>1</td>\n",
       "      <td>108.0</td>\n",
       "      <td>11304.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>32365 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        patientunitstayid  mv_apache  mvstart    mvend  mv_treatment\n",
       "4709               242154          1    204.0   4683.0             1\n",
       "4732               243283          1     33.0    503.0             1\n",
       "4735               243494          1    392.0   3851.0             1\n",
       "4737               243643          1     77.0    142.0             1\n",
       "4745               243990          1    103.0    125.0             1\n",
       "4751               244255          0   -389.0   -306.0             1\n",
       "4757               244445          1    184.0   3162.0             1\n",
       "4763               244718          1     27.0   1134.0             1\n",
       "4765               244763          0    993.0   1125.0             1\n",
       "4767               244975          1     74.0   1601.0             1\n",
       "4775               245542          1    151.0    151.0             1\n",
       "4784               245956          1    118.0   1257.0             1\n",
       "4785               246128          1     87.0     87.0             1\n",
       "4787               246393          1    104.0   1609.0             1\n",
       "4790               246449          1     78.0     78.0             1\n",
       "4792               246531          1    131.0    131.0             1\n",
       "4798               246953          1     25.0   1374.0             1\n",
       "4800               247030          1     50.0     50.0             1\n",
       "4801               247048          1     45.0     45.0             1\n",
       "4802               247164          1    851.0   2255.0             1\n",
       "4803               247206          1    213.0   1471.0             1\n",
       "4804               247249          0   2088.0   2088.0             1\n",
       "4807               247296          1    149.0   4272.0             1\n",
       "4808               247363          1    142.0    540.0             1\n",
       "4809               247408          1   1259.0   8363.0             1\n",
       "4814               247748          1     32.0     32.0             1\n",
       "4820               247872          1     48.0   1038.0             1\n",
       "4821               247888          1     77.0   4168.0             1\n",
       "4828               248438          1    375.0    375.0             1\n",
       "4830               248581          1     11.0  26621.0             1\n",
       "...                   ...        ...      ...      ...           ...\n",
       "136147            3352097          1     47.0     47.0             1\n",
       "136148            3352103          1    134.0    134.0             1\n",
       "136149            3352114          1     75.0     75.0             1\n",
       "136150            3352119          1    109.0    129.0             1\n",
       "136151            3352125          1     84.0   1304.0             1\n",
       "136153            3352178          1    145.0    145.0             1\n",
       "136155            3352203          1    137.0   4370.0             1\n",
       "136163            3352336          1     59.0     59.0             1\n",
       "136164            3352340          1    203.0    203.0             1\n",
       "136165            3352344          1     99.0     99.0             1\n",
       "136167            3352402          1     44.0     44.0             1\n",
       "136168            3352437          1     96.0   7382.0             1\n",
       "136170            3352445          1    451.0   7922.0             1\n",
       "136176            3352526          1    321.0   7224.0             1\n",
       "136181            3352546          1     67.0    714.0             1\n",
       "136182            3352569          1     11.0   2256.0             1\n",
       "136187            3352618          1     84.0   9412.0             1\n",
       "136188            3352620          0   2051.0   2051.0             1\n",
       "136191            3352711          1     80.0   6212.0             1\n",
       "136192            3352721          1    308.0  20292.0             1\n",
       "136201            3352801          1    309.0    310.0             1\n",
       "136202            3352827          0   1192.0  21916.0             1\n",
       "136204            3352861          1    140.0    598.0             1\n",
       "136217            3352986          1    453.0  51720.0             1\n",
       "136221            3353031          1     95.0     95.0             1\n",
       "136225            3353092          1     46.0     46.0             1\n",
       "136229            3353144          1    103.0  11217.0             1\n",
       "136231            3353194          1     52.0   2212.0             1\n",
       "136232            3353226          1     81.0  10522.0             1\n",
       "136234            3353251          1    108.0  11304.0             1\n",
       "\n",
       "[32365 rows x 5 columns]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[~df['mvstart'].isnull(),:]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.5",
   "language": "python",
   "name": "python35"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
